﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;

namespace TVShow.Framework
{
  class Shell
  {
    public static string AppPath() {
      return System.Windows.Forms.Application.StartupPath;
    }

    public static string AppPath(string FileName) {
      return System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, FileName);
    }

    public static void Launch(string FileName) {
      Launch(FileName, "", false);
    }

    public static void Launch(string FileName, string Arguments) {
      Launch(FileName, Arguments, false);
    }

    public static void LaunchFromAppDir(string FileName, string Arguments, bool WaitForExit) {
      string fn = AppPath(FileName);
      Launch(fn, Arguments, WaitForExit);
    }

    public static void Launch(string FileName, string Arguments, bool WaitForExit) {
      string output;

      Process proc = new Process();
      proc.StartInfo.UseShellExecute = false;
      proc.StartInfo.RedirectStandardOutput = true;

      proc.EnableRaisingEvents = false;
      proc.StartInfo.FileName = FileName;
      if (Arguments != "") proc.StartInfo.Arguments = Arguments;
      proc.Start();

      if (WaitForExit) {
        proc.WaitForExit();
        output = proc.StandardOutput.ReadToEnd();
        Debug.WriteLine(output);
      }
    }
  }
}
